<?php
$section = 'banner';
$titre = _LB_BANNER_MANAGEMENT;
$smarty->assign("titre", $titre);

Session::setBackLink($section);

$module = Module::getList();

$filter = array();
$filter['NAME'] = trim(Request::get('NAME'));
$filter['ID_MODULE'] = Request::getIntNumber('ID_MODULE');
$filter['STATUS'] = Request::getIntNumber('STATUS');

$banner = new Banner();

$whereAdd = "TRUE";
if ($filter['NAME'] != '') {
	$whereAdd .= " AND (NAME like '%".$banner->escape($filter['NAME'], TRUE)."%')";
}
if ($filter['ID_MODULE'] != 0) {
	$mod = $filter['ID_MODULE'];
	$whereAdd .= " AND (ID_MODULE = {$mod})";
}
if ($filter['STATUS'] != 0) {
	$status = $filter['STATUS'] - 1;
	$whereAdd .= " AND (DISABLED = {$status})";
}

$query = "	SELECT DISTINCT BANNER.*
			FROM BANNER 
			LEFT JOIN BANNER_MODULE
				ON BANNER.ID = BANNER_MODULE.ID_BANNER 
			WHERE $whereAdd ORDER BY NAME ASC";

$args = array();
$pager = new  DBPager($banner, $args, false ,PAGING_DEFAULT_ITEM_PER_PAGE,$query);
$banner->query($query);

$cfer = new Cfer(array(
	_LB_ACCUEIL => Utils::getHomeLink(),
	_LB_BANNER_MANAGEMENT => Utils::getCurrentLink())
);

$smarty->assign('cfer', $cfer);
$smarty->assign('banner', $banner);
$smarty->assign('module', $module);
$smarty->assign('filter', $filter);
$smarty->assign('pager', $pager);

$smarty->display('banner_list.html');